<?php
/**
 * 定义validator控件
 * 
 * 控件名标识了校验规则，可以使用message参数指定校验失败时提示的消息
 * 
 * - <v:required message="这个字段不能为空"/>
 * - <v:length min=1 max=10 message="字段值太长或太短" />
 * 
 * 所有的校验规则都定义在IFormValidator类中
 *
 * @package if
 * @subpackage module.ui
 * @since 1.1.0
 * @see IValidator
 */
class UIValidator extends UIControl {
	protected $reserveAttrs = array();
	
	private $rule;
	private $params;
	private $message;
	
	function rule() {
		return $this->rule;
	}
	
	function params() {
		return $this->params;
	}
	
	function message() {
		return $this->message;
	}
	
	function parse() {
		list($prefix, $this->rule) = explode(":", $this->name(), 2);
		$this->params = $this->attrs();
		if ($this->rule == "method") {
			$rule = $this->attr("rule");
			if ($rule) {
				unset($this->params["rule"]);
			}
			if (!isset($rule["class"])) {
				$rule["class"] = $this->controller;
			}
			if (isset($rule["name"])) {
				$this->rule = array($rule["class"], $rule["name"]);
				$this->params["controlId"] = $this->parent()->id();
			}
		}
		if (isset($this->params["message"])) {
			$this->message = $this->params["message"];
			unset($this->params["message"]);
		}
	}
	
	function render() {
		return "";
	}
}

?>